//
//  GooglePasswordView.m
//  bitcoin
//
//  Created by caiyajun on 2018/6/7.
//  Copyright © 2018年 比特币. All rights reserved.
//

#import "GooglePasswordView.h"
#import "CodeView.h"
@interface GooglePasswordView()

@property (weak, nonatomic) IBOutlet UIView *contentView;
@property (weak, nonatomic) IBOutlet UIView *closeView;

@end
@implementation GooglePasswordView

+ (instancetype)xib
{
    return [[NSBundle mainBundle] loadNibNamed:@"GooglePasswordView" owner:self options:nil][0];
}
- (void)awakeFromNib
{
    [super awakeFromNib];
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    view.backgroundColor = [UIColor blackColor];
    view.alpha = 0.75;
    [self addSubview:view];
    self.alpha = 1;
    self.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight);
    [self addSubview:self.closeView];
    [self addSubview:self.contentView];
    
    CodeView *codeView = [[CodeView alloc] initWithFrame:CGRectMake(0, 100, ScreenWidth, 60)
                                              num:6
                                        lineColor:[UIColor whiteColor]
                                         textFont:24];
    codeView.backgroundColor=[UIColor clearColor];
    //下划线
    codeView.hasUnderLine = YES;
    //分割线
    codeView.hasSpaceLine = NO;
    
    //输入风格
    codeView.codeType = CodeViewTypeCustom;
    codeView.EndEditBlcok = ^(NSString *str) {
        if (self.submitActionBlock) {
            self.submitActionBlock(str);
        }
    };
    [self.contentView addSubview:codeView];
    
    UITapGestureRecognizer *tapGesturRecognizer=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction)];
    
    [self.closeView addGestureRecognizer:tapGesturRecognizer];
    //增加监听，当键盘出现或改变时收出消息
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    //增加监听，当键退出时收出消息
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}


//当键盘出现或改变时调用
- (void)keyboardWillShow:(NSNotification *)aNotification {
    //获取键盘的高度
    NSDictionary *userInfo = [aNotification userInfo];
    NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect keyboardRect = [aValue CGRectValue];
    int height = keyboardRect.size.height;
    self.contentView.frame=CGRectMake(0, ScreenHeight-270-height, ScreenWidth, 341);
    
}
- (void)keyboardWillHide:(NSNotification *)aNotification {

    
    self.contentView.frame=CGRectMake(0, ScreenHeight-341, ScreenWidth, 341);
    
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self endEditing:YES];
}

- (void)tapAction{
    [self removeFromSuperview];
}






@end
